/*
 * 系统项目名称：综合决策分析系统-version2.0
 * 文件名：ShopCompanyServiceImpl.java
 * 描述：
 * 版权：Copyright 2015-2020 义乌市跨境电商供应链管理有限公司-版权所有
 * 修改人：yangjx
 * 修改时间：2016-3-11 下午1:45:34
 * 版本号：V1.1
 */
package com.ywt.cda.service.impl;

import com.ywt.cda.action.model.ConsmersModel;
import com.ywt.cda.dao.Ana1stDataDao;
import com.ywt.cda.dao.Ana2ndDataDao;
import com.ywt.cda.dao.AnaImportDataDao;
import com.ywt.cda.domain.*;
import com.ywt.cda.domain.enums.AnaTable;
import com.ywt.cda.domain.enums.DimensionFlag;
import com.ywt.cda.domain.enums.OrderByEnum;
import com.ywt.cda.service.ConfDataCacheService;
import com.ywt.cda.service.ConsumersService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * （一句话功能简述）
 * <br>（功能详细描述）
 * @author lougf
 * @version V1.0
 * @see [相关类/方法]
 * @since 2016-3-11 下午1:45:34
 */
@Service
public class ConsumersServiceImpl implements ConsumersService {

	@Resource
	private Ana2ndDataDao ana2ndDataDao;
	@Resource
	private Ana1stDataDao ana1stDataDao;
	@Resource
	private AnaImportDataDao anaImportDataDao;
	@Resource
	private ConfDataCacheService cdc;
	private final String YYYY_MM="yyyy-MM";


	@Override
	public List<AnaImportData> getImortDataByCategory(ConsmersModel model) {
		AnaTable table=AnaTable.TB_ANA_DATA_IMPORT_3RD_D;
		if(YYYY_MM.equals(model.getStartTimePattern())){
			table=AnaTable.TB_ANA_DATA_IMPORT_3RD_M;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("tableName", table.getTableName());
		params.put("groupCode", "SECOND_CODE");
		params.put("endDate", model.getEndTime_F());
		params.put("startDate", model.getStartTime_F());
		params.put("orderBy", OrderByEnum.SUM_NUM.name());
		params.put("secondFlag", DimensionFlag.M_CATEGORY.getCode());

		return anaImportDataDao.listTotalDataByParamsAndGoods(params);
	}

	@Override
	public List<AnaImportData> getImortDataBySex(ConsmersModel model) {
		AnaTable table=AnaTable.TB_ANA_DATA_IMPORT_3RD_D;
		if(YYYY_MM.equals(model.getStartTimePattern())){
			table=AnaTable.TB_ANA_DATA_IMPORT_3RD_M;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("tableName", table.getTableName());
		params.put("groupCode", "SECOND_CODE");
		params.put("endDate", model.getEndTime_F());
		params.put("startDate", model.getStartTime_F());
		params.put("orderBy", OrderByEnum.SUM_NUM.name());
		params.put("secondFlag", DimensionFlag.SEX_TYPE.getCode());
		return anaImportDataDao.listTotalDataByParamsAndGoods(params);
	}

	@Override
	public List<AnaImportData> getImortDataByAge(ConsmersModel model) {
		AnaTable table=AnaTable.TB_ANA_DATA_IMPORT_3RD_D;
		if(YYYY_MM.equals(model.getStartTimePattern())){
			table=AnaTable.TB_ANA_DATA_IMPORT_3RD_M;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("tableName", table.getTableName());
		params.put("groupCode", "substr(SECOND_CODE,0,4)");
		params.put("asName", " as SECOND_CODE");
		params.put("endDate", model.getEndTime_F());
		params.put("startDate", model.getStartTime_F());
		params.put("orderBy", OrderByEnum.SUM_NUM.name());
		params.put("secondFlag", DimensionFlag.AGE_TYPE.getCode());
		return anaImportDataDao.listTotalDataByParamsAndGoods(params);
	}

	@Override
	public List<AnaImportData> getImportData(ConsmersModel model)
	{
		AnaTable table=AnaTable.TB_ANA_IMPORT_3RD_D;
		if(YYYY_MM.equals(model.getStartTimePattern())){
			table=AnaTable.TB_ANA_IMPORT_3RD_M;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("tableName",table.getTableName());
		params.put("groupCode", "SECOND_CODE");
		params.put("endDate", model.getEndTime());
		params.put("startDate", model.getStartTime());
		params.put("orderBy", OrderByEnum.SUM_NUM.name());
		params.put("secondFlag",DimensionFlag.S_CATEGORY.getCode());
		params.put("mainCode",model.getSex());
		params.put("mainFlag",DimensionFlag.SEX_TYPE.getCode());
		return anaImportDataDao.listTotalDataByParamsAndGoods(params);
	}

	
}
